package com.longrou.base.base

import android.app.Activity
import android.content.Context
import android.support.v4.app.Fragment
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.launcher.ARouter
import com.scwang.smartrefresh.layout.api.RefreshLayout

/**
 * @Description:
 * @Author: LongRou
 * @CreateDate: 2018-05-18 23:16
 * @Version: 1.0
 **/
abstract class BaseFragment : Fragment() {
    protected var mActivity: Activity? = null

    /**
     * 获得全局的，防止使用getActivity()为空
     * @param context
     */
    override fun onAttach(context: Context) {
        super.onAttach(context)
        this.mActivity = context as Activity
    }

    protected fun buildActivity(path: String): Postcard {
        return ARouter.getInstance().build(path)
    }

    fun openActivity(path: String) {
        ARouter.getInstance().build(path).navigation()
    }

    fun openActivityAndFinish(path: String) {
        ARouter.getInstance().build(path).navigation()
        mActivity?.finish()
    }

    fun dataOnRefresh(refreshlayout: RefreshLayout) {

    }

    fun dataOnLoadmore(refreshlayout: RefreshLayout) {

    }
    /*protected Activity mActivity;

    */
    /**
     * 获得全局的，防止使用getActivity()为空
     * @param context
     *//*
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mActivity = (Activity)context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container
            , Bundle savedInstanceState) {

        View view = LayoutInflater.from(mActivity)
                .inflate(getLayoutId(), container, false);
        initView(view, savedInstanceState);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    */
    /**
     * 该抽象方法就是 onCreateView中需要的layoutID
     * @return
     *//*
    protected abstract int getLayoutId();

    */
    /**
     * 该抽象方法就是 初始化view
     * @param view
     * @param savedInstanceState
     *//*
    protected abstract void initView(View view, Bundle savedInstanceState);

    */
    /**
     * 执行数据的加载
     *//*
    protected abstract void initData();*/
}